<!DOCTYPE html>
<!--suppress ALL -->
<html lang="en">
<head>
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <title>back-duty</title>
        <link rel="stylesheet" href="/admin/layui-v2.4.5/layui/css/layui.css"  media="all">
        <link rel="stylesheet" href="/admin/css/admin.css"  media="all">
        <style>
            .selected_keywords{
                display: none;
                position: absolute;
                left: 0;
                top: 42px;
                padding: 5px 0;
                z-index: 899;
                min-width: 100%;
                border: 1px solid #d2d2d2;
                max-height: 300px;
                overflow-y: auto;
                background-color: #fff;
                border-radius: 2px;
                box-shadow: 0 2px 4px rgba(0,0,0,.12);
                box-sizing: border-box;
            }
            .list-group{
                padding: 0 10px;
                line-height: 36px;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
            }
            .list-group > li hover{
                background-color: #5FB878;
                color: #fff;
            }

        </style>
    </head>
<body>

<script src="/admin/layui-v2.4.5/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="/admin/js/jquery.js"></script>

<script type="text/html" id="selectUser" >
    <form class="layui-form">
        <select name="selectUser1" id="selectUser1" lay-verify="required" lay-filter="user-select"> </select>
    </form>
</script>


<table class="layui-table"  id='Demo' lay-filter="Demo">
</table>

<script>
    var dictNameOptions = "<option value=''>请选择</option>\n";
    $.ajax({
        ansyc: false,
        url: "/hospital/allUser",
        type: "post",
        // contentType:"application/json;charset=utf-8",
        dataType: "json",
        success: function (data) {
            for (var x in data) {
                dictNameOptions += '<option value = "' + data[x].userId + '">' + data[x].ad_name + '</option>\n';
            }

            /*  layui.use('form', function () {
                  var form = layui.form;
                  $("#selectUser1").html("");
                  $("#selectUser1").append("<option value=''>请选择</option>");
                  $.each(data, function (index, ele) {
                      $("#selectUser1").append("<option value='" + ele.userId + "'>" + ele.ad_name + "</option>");
                  });
                  form.render('select');
              });*/

        },
        error: function () {
            alert("数据加载失败！");
        }
    });
    $(function () {
        fn();
    });
    layui.use('form',function () {
        var form=layui.form;
        form.render('select');
    });
    layui.use('table', function(){
        var table = layui.table;

        table.render({
            elem: '#Demo',
            url: './json/duty.js'

            ,cols: [
                [   {field: 'time',  title: '时间',align: 'center',width:100},
                    {field: 'mon', edit: 'text',title: '星期一',align: 'center', },
                    {field: 'tue', edit: 'text',title: '星期二',align: 'center'},
                    {field: 'wed', edit: 'text',title: '星期三',align: 'center'},
                    {field: 'thu', edit: 'text',title: '星期四',align: 'center'},
                    {field: 'fri', edit: 'text',title: '星期五',align: 'center'},
                    {field: 'sat', edit: 'text',title: '星期六',align: 'center'},
                    {field: 'sun', edit: 'text',title: '星期日',align: 'center'}
                ]
            ],
            done: function (res, curr, count) {
                // 渲染dictName列
                // 渲染之前组装select的option选项值
                console.log('打印dictNameOptions');
                console.log(dictNameOptions);
               /* $("select[name='tue']").html(dictNameOptions);*/
                $("#selectUser1").append(dictNameOptions);
                layui.each($("select[name='tue']"), function (index, item) {
                    var elem = $(item);
                    elem.val(elem.data('value'));
                });
                layui.form.render('select');
            },
            id: 'DemoTable',
            toolbar:true,
            defaultToolbar: [ 'print', 'exports']
        });



        table.on('tool(Demo)', function(obj){
            var data = obj.data;
            if(obj.event === 'setSign'){
                var index = layer.open({
                    type: 2,
                    area: ['300px', '300px'],
                    fixed: false,
                    maxmin: true,
                    shadeClose: true,
                    content: 'back_edit.html',
                });

            }

        })

        $.ajax({
            ansyc: false,
            url: "/hospital/duty",
            type: "get",
            contentType:"application/json;charset=utf-8",
            dataType: "json",
            success: function (data) {
                $.each(data.data, function (index, item) {
                    var i=item.weizhi;
                    var j=item.remark;
                    $('tbody').find('tr').eq(i).find("td").eq(j).eq(0).text(item.name);
                });
            },
            error: function () {
                alert("数据加载失败！");
            }
        });
        // var tdArr = parent.$('tbody').find('tr').find("td").eq(1);
        // //td里的内容
        // var name1 = $(tdArr.eq(0)).text(name);
        // $(tdArr.eq(1)).text("dfg");
        //头工具栏事件
        table.on('toolbar(Demo)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheck':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
            };
        });
        //监听单元格编辑
        // 监听值的修改，把要修改的id与input框的值用ajax提交给后台更新
        table.on('edit(Demo)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
            console.log(obj.value)
            layer.msg('[time: '+ data.time +'] ' + field + ' 字段更改为：'+ value);
            $.ajax({
                ansyc: false,
                url: "/hospital/updateduty",
                type: "post",
                contentType:"application/json;charset=utf-8",
                dataType: "json",
                data:JSON.stringify({
                    "field":field,
                    "value":value
                }),
                success: function (e) {
                    // $.each(data.data, function (index, item) {
                    //     var i=item.weizhi;
                    //     var j=item.remark;
                    //     $('tbody').find('tr').eq(i).find("td").eq(j).eq(0).text(item.name);
                    // });
                    if (e.code == 1) {
                        layer.msg("更改成功");
                    } else {
                        layer.msg("更改失败");
                    }
                }
            });




        });
    });

    function fn() {

    }



</script>
</body>
</html>